<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- 输入框 -->
      <el-row>
        <el-col :span="10">
          <el-input placeholder="请输入内容" v-model="value" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="orderList" border stripe>
        <el-table-column label="#" type="index">
        </el-table-column>
        <el-table-column label="订单编号" prop="order_number" width="250px">
        </el-table-column>
        <el-table-column label="订单价格" prop="order_price">
        </el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template v-slot="{row}">
            <el-tag v-if="row.pay_status==='0'" type="danger" effect="dark" size="mini">未付款</el-tag>
            <el-tag v-else type="success" effect="dark" size="mini">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send">
        </el-table-column>
        <el-table-column label="下单时间" prop="update_time">
          <template v-slot="{row}">
            {{row.update_time | dataFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120px">
          <template v-slot="">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editDialogVisible=true"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="showExpressDialog"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum" :page-sizes="[3, 5, 10, 15]" :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="50%">
      <el-cascader v-model="cityList" :options="cityData" @change="cityHandleChange"></el-cascader>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息对话框 -->
    <el-dialog title="物流进度" :visible.sync="expressDialog" width="50%">
      <!-- 时间线 -->
      <el-timeline :reverse="false">
        <el-timeline-item v-for="(item, index) in expressList" :key="index" :timestamp="item.time">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="expressDialog = false">取 消</el-button>
        <el-button type="primary" @click="expressDialog = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      value: '',
      queryInfo: {
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      // 订单列表
      orderList: [],
      // 修改地址对话框显隐
      editDialogVisible: false,
      cityData,
      // 城市级联数据
      cityList: [],
      // 物流对话框显隐
      expressDialog: false,
      // 物流进度
      expressList: []
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 渲染列表
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })

      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 页码变化
    handleSizeChange (size) {
      this.queryInfo.pagesize = size
      this.getOrderList()
    },
    // 当前页变化
    handleCurrentChange (current) {
      this.queryInfo.pagenum = current
      this.getOrderList()
    },
    // 级联
    cityHandleChange () {
    },
    // 物流
    async showExpressDialog () {
      this.expressDialog = true
      // const { data: res } = await this.$http.get('http://localhost:8082/api/express')
      const { data: res } = await this.$http.get('https://www.liulongbin.top:8888/api/private/v1/kuaidi/1106975712662')
      console.log(res)
      this.expressList = res.data
    }
  }

}
</script>

<style scoped lang='less'>
.el-cascader {
  width: 100%;
}
</style>
